/** Lachlan Hewson-Doherty (h201384171)
 *  Diploma of Digital and Interactive Games
 *  lachlan_doherty@live.com.au
 *  2013
 */

package cabbage.database.operations;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import cabbage.database.utilities.DatabaseConnection;



public class LiveCollectibleCreationOps {
	
	
	
	
	
	private DatabaseConnection db;
	
	
	
	
	public int insertNewLiveCollectible(int collectiblemaster_id, int location_id) throws SQLException {
		
		db = new DatabaseConnection
								();
		
		Connection conn = db.getConnection
									();
		PreparedStatement ps = conn.prepareStatement
								("INSERT INTO livecollectible (collectiblemaster_id,location_id,available) VALUES (?,?,1)",
										Statement.RETURN_GENERATED_KEYS);
		
		ps.setInt
				(1, collectiblemaster_id);
		
		ps.setInt
				(2, location_id);
		
		ps.execute
				();
		

		ResultSet rskey = ps.getGeneratedKeys
											();
		

		if (rskey.next()) {
			
			int newAccountID = rskey.getInt(1);
			conn.close();
			return newAccountID;
			
		}
		
		conn.close();
		return 0;
		
	}

}
